package com.elric.mall.controller;

import cn.hutool.core.util.StrUtil;
import com.elric.mall.mapper.ProjectEntityNewDao;
import com.elric.mall.mapper.ProjectMapper;
import com.elric.mall.common.api.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@RestController
@RequestMapping("/project")
public class ProjectController {
    @Autowired
    ProjectMapper projectMapper;

    @Autowired
    ProjectEntityNewDao projectEntityNewDao;

    @GetMapping("/getCount")
    public CommonResult getProjectCount() {
        return CommonResult.success(projectMapper.getCount());
    }

    @GetMapping("/getAmount")
    public CommonResult getProjectAmount() {
        Integer amount = projectMapper.getAmount();
        if (amount == null) {
            return CommonResult.success(0);
        }
        return CommonResult.success(amount);
    }

    @GetMapping("/getProjectLevel")
    public CommonResult getProjectLevel() {
        return CommonResult.success(projectMapper.groupByZyx());
    }

    @GetMapping("/getProjectSsjz")
    public CommonResult getProjectSsjz() {
        return CommonResult.success(projectMapper.groupByJZ());
    }

    @GetMapping("/getProjectField")
    public CommonResult getProjectField() {
        return CommonResult.success(projectMapper.groupByZq());
    }

    @GetMapping("/getUnitList")
    public CommonResult getUnitList() {
        return CommonResult.success(projectMapper.getUnitList());
    }

    @GetMapping("/getLevelByUnit")
    public CommonResult getLevelByUnit(@RequestParam String unitName) {
        return CommonResult.success(projectMapper.getLevelDataByUnit(unitName));
    }

    @GetMapping("/getZjdwByUnit")
    public CommonResult getZjdwByUnit(@RequestParam String unitName) {
        return CommonResult.success(projectMapper.getZjdwByUnit(unitName));
    }

    @GetMapping("/getAreaDataByUnit")
    public CommonResult getAreaDataByUnit(@RequestParam String unitName) {
        return CommonResult.success(projectMapper.getAreaDataByUnit(unitName));
    }

    @GetMapping("/getSsjzDataByUnit")
    public CommonResult getSsjzDataByUnit(@RequestParam String unitName) {
        return CommonResult.success(projectMapper.getSsjzDataByUnit(unitName));
    }

    @GetMapping("/getPowerDataByUnit")
    public CommonResult getPowerDataByUnit(@RequestParam String unitName) {
        return CommonResult.success(projectMapper.getPowerDataByUnit(unitName));
    }

    @GetMapping("/getLevelData")
    public CommonResult getLevelData() {
        return CommonResult.success(projectMapper.getLevelData());
    }

    @GetMapping("/getZztxDataByLevel")
    public CommonResult getZztxDataByLevel(@RequestParam String unitName) {
        return CommonResult.success(projectMapper.getZztxDataByLevel(unitName));
    }

    @GetMapping("/getJsxzDataByLevel")
    public CommonResult getJsxzDataByLevel(@RequestParam String unitName) {
        return CommonResult.success(projectMapper.getJsxzDataByLevel(unitName));
    }

    @GetMapping("/getNltxDataByLevel")
    public CommonResult getNltxDataByLevel(@RequestParam String unitName) {
        return CommonResult.success(projectMapper.getNltxDataByLevel(unitName));
    }

    @GetMapping("/getSsjzDataByLevel")
    public CommonResult getSsjzDataByLevel(@RequestParam String unitName) {
        return CommonResult.success(projectMapper.getSsjzDataByLevel(unitName));
    }

    @GetMapping("/getFieldsDataByLevel")
    public CommonResult getFieldsDataByLevel(@RequestParam String unitName) {
        return CommonResult.success(projectMapper.getFieldsDataByLevel(unitName));
    }

    @GetMapping("/getUnitDataByLevel")
    public CommonResult getUnitDataByLevel(@RequestParam String unitName) {
        return CommonResult.success(projectMapper.getUnitDataByLevel(unitName));
    }

    @GetMapping("/queryCountByLocation")
    public CommonResult queryCountByLocation() {
        return CommonResult.success(projectMapper.queryCountByLocation());
    }

    @GetMapping("/list")
    public CommonResult getProjectList(@RequestParam(value = "name", required = false) String name) {
        if (StrUtil.isBlank(name)) {
            return CommonResult.success(projectEntityNewDao.findAll());
        }
        return CommonResult.success(projectMapper.getProjectList(name));
    }

    @GetMapping("/getProcessList")
    public CommonResult getProcessList() {
        return CommonResult.success(projectMapper.getProcessList());
    }

    @GetMapping("/getProjectByGroup")
    public CommonResult getProjectByGroup() {
        return CommonResult.success(projectMapper.getProjectByGroup());
    }

    @GetMapping("/getJiqunCountByProject")
    public CommonResult getJiqunCountByProject(@RequestParam(value = "unitName", required = false) String unitName) {
        return CommonResult.success(projectMapper.getJiqunCountByProject(unitName));
    }

    @GetMapping("/getUnitCountByProject")
    public CommonResult getUnitCountByProject(@RequestParam(value = "unitName", required = false) String unitName) {
        return CommonResult.success(projectMapper.getUnitCountByProject(unitName));
    }

    @GetMapping("/getStatusByProject")
    public CommonResult getStatusByProject(@RequestParam(value = "unitName", required = false) String unitName) {
        return CommonResult.success(projectMapper.getStatusByProject(unitName));
    }

    @GetMapping("/getLevelByProject")
    public CommonResult getLevelByProject(@RequestParam(value = "unitName", required = false) String unitName) {
        return CommonResult.success(projectMapper.getLevelByProject(unitName));
    }

    @GetMapping("/getFieldByProject")
    public CommonResult getFieldByProject(@RequestParam(value = "unitName", required = false) String unitName) {
        return CommonResult.success(projectMapper.getFieldByProject(unitName));
    }

    @GetMapping("/getProcessListByUpperUnit")
    public CommonResult getProcessListByUpperUnit(@RequestParam(value = "status", required = false) String status) {
        return CommonResult.success(projectMapper.getProcessListByUpperUnit(status));
    }

    @GetMapping("/getProcessListBySsjz")
    public CommonResult getProcessListBySsjz(@RequestParam(value = "status", required = false) String status) {
        return CommonResult.success(projectMapper.getProcessListBySsjz(status));
    }

    @GetMapping("/getProcessListByNltx")
    public CommonResult getProcessListByNltx(@RequestParam(value = "status", required = false) String status) {
        return CommonResult.success(projectMapper.getProcessListByNltx(status));
    }

    @GetMapping("/getProcessListByLevel")
    public CommonResult getProcessListByLevel(@RequestParam(value = "status", required = false) String status) {
        return CommonResult.success(projectMapper.getProcessListByLevel(status));
    }

    @GetMapping("/getProjectProcessList")
    public CommonResult getProjectProcessList(@RequestParam(value = "status", required = false) String status) {
        return CommonResult.success(projectMapper.getProjectProcessList(status));
    }
}
